// pages/my_reservation/my_reservation.js
const db = wx.cloud.database();
const _ = db.command;

var appUser = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_img:"",
    user_name:"",
    user_id:"",
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.setData({
      user_img: appUser.globalData.userImg,
      user_name: appUser.globalData.userName
    });
    db.collection('user2').where({
      avatarUrl: this.data.user_img,
      nickName: this.data.user_name
    }).get({
      success:res=>{
        // console.log(res.data[0]._openid)
        db.collection('beadhouseOrder').where({
          _openid:res.data[0]._openid
        }).get({
          success:res1=>{
            // console.log(res1.data)
            this.setData({
              list:res1.data
            })
            console.log(this.data.list[0].id)
            for (var i = 0; i < this.data.list.length; i++) {
              console.log("函数外：" + i)
              this.wait(i)
            }

          }
        })
      }
    })
  },
abc(){
  console.log(this.data.list[0].id)
},
  async wait(i) {
    db.collection('beadhouselist').where({
      id: this.data.list[i].id
    }).get().then(res => {
      // console.log("函数里：" + i)
       this.data.list[i].id=res.data[0].name
       console.log(this.data.list[i].id);
       this.setData({
        list:this.data.list
      })
    })
    return;
  }
})